package com.shanjiduo.newsline;

import android.app.ProgressDialog;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

public class WebActivity extends AppCompatActivity {

    private WebView wv;
    private String url;
    private ProgressDialog bar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web);
        Intent intent = getIntent();
        url = intent.getStringExtra("url");
        initView();

    }

    private void initView() {
        wv = (WebView) findViewById(R.id.news_webview);
        wv.loadUrl(url);

        WebSettings set = wv.getSettings();
        set.setJavaScriptCanOpenWindowsAutomatically(true);
        set.setJavaScriptEnabled(true);
        bar = new ProgressDialog(this);
        bar.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        bar.setProgress(0);
        bar.setMax(100);
        wv.setWebViewClient(new WebViewClient());
        wv.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                super.onProgressChanged(view, newProgress);
                bar.setProgress(newProgress);
                bar.show();
                if (newProgress == 100) {
                    bar.dismiss();
                }
            }
        });
    }

}
